package top.codetheory.thread._003_park;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.LockSupport;

/**
 * @author: CodeTheory
 * @since: 2024/4/27 下午3:34
 **/
@Slf4j
public class _002_测试多次调用park {
    /**
     * 可以看到t1线程在第二次调用park后, 会等待别的线程给他unpark, 会一直等待 <br>
     *<img src="https://gitee.com/codetheory/img-on1/raw/master/img01/1714203375147-2024-4-2715:36:15.png"  />
     * @param args
     * @throws InterruptedException
     */
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            log.info("t1线程第一次调用park");
            LockSupport.park();
            log.info("t1线程第二次调用park");
            LockSupport.park();
            log.info("t1线程执行完毕");
        }, "t1");
        t1.start();


        Thread.sleep(1000);
        log.info("main线程第一次调用unpark");
        LockSupport.unpark(t1);
        log.info("main线程执行完毕");
        Thread.sleep(100000);
    }
}